<template>
	<view class="content">
		<u-tabs :list="tabList" @click="click" :scrollable="false" lineWidth="40"></u-tabs>
		<view class="list">
			<view class="list-item" v-for="item in list" :key="item.id" @click="goDetails(item)">
				<image :src="item.houseImg" mode="widthFix"></image>
				<text class="name">{{item.name}}</text>
				<view class="tips-box">
					<text class="tips">{{item.houseType}}</text>
					<text class="price">{{item.price}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabList: [{
					name: '所有',
					id: ''
				}, {
					name: '毛坯',
					id: 0
				}, {
					name: '精装修',
					id: 1
				}, {
					name: '简装修',
					id: 2
				}],
				list: [],
				isShow: false
			}
		},
		onLoad(op) {
			this.getHousingResourcesInfoList()
			if (op.page && op.page == 'yuyue') {
				this.isShow = true
			} else {
				this.isShow = false
			}
		},
		methods: {
			//获取房源数据
			async getHousingResourcesInfoList(state) {
				const res = await this.$api.getHousingResourcesInfoList({
					pageIndex: -1,
					pageSize: -1,
					renovation: state
				})
				// console.log(res)
				this.list = res.records
			},
			click(item) {
				this.getHousingResourcesInfoList(item.id)
			},
			goDetails(item) {
				uni.navigateTo({
					url: '/pages/details/details?data=' + JSON.stringify(item) + '&page=' + this.isShow
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: column;

		.list {
			display: flex;
			margin-top: 40rpx;
			padding: 0 40rpx;
			flex-wrap: wrap;
			justify-content: space-between;

			.list-item {
				width: 320rpx;
				display: flex;
				flex-direction: column;
				border-radius: 20rpx;
				margin-top: 40rpx;
				overflow: hidden;
				box-shadow: 2px 2px 10px 2px rgba(0, 0, 0, .2);

				image {
					width: 100%;
				}

				.name {
					font-size: 32rpx;
					padding: 20rpx;
				}

				.tips-box {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 0 10rpx;
					margin-bottom: 20rpx;

					.tips {
						font-size: 28rpx;
						padding: 4rpx 8rpx;
						font-size: 28rpx;
						color: #849aae;
						background-color: rgba(132, 154, 174, .1);
						border-radius: 4rpx;
					}

					.price {
						font-size: 28rpx;
						color: red;
					}
				}
			}
		}
	}
</style>